package com.ljfresh.customer.configuration;

import com.ljfresh.customer.interceptor.ApiAuthInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author: Lucifer
 * @time: 2020/4/28-9:52
 */
//@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {

    @Bean
    public ApiAuthInterceptor apiAuthInterceptor(){
        return new ApiAuthInterceptor();
    }

    /**
     * 在springboot2.0.0之后继承WebMvcConfigurationSupport类，重写addInterceptors方法
     *
     * @param registry
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        /**
         * 拦截器按照顺序执行,如果不同拦截器拦截存在相同的URL，前面的拦截器会执行，后面的拦截器将不执行
         */
        registry.addInterceptor(apiAuthInterceptor())
                .addPathPatterns("/**");
        super.addInterceptors(registry);
    }
}
